<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
<div class="page-header">
	<h1>资源出版社管理</h1>
</div>
<div class="col-xs-12">
    <a href="#modal-publisher" class="btn btn-primary" data-toggle="modal">
			<i class="ace-icon fa fa-plus"></i> 新增资源出版社
	</a>
	<table id="dynamic-table" class="table table-striped table-bordered table-hover" style="margin-top:10px">
		<thead>
			<tr>
				<th>标题</th>
                <th>创建时间</th>
                <th>修改时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>
<!-- 新增出版社弹窗 -->
<div id="modal-publisher" class="modal fade">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header no-padding">
				<div class="table-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						<span class="white">&times;</span>
					</button> <span id="school-name"></span>
					编辑资源出版社
				</div>
			</div>
			<div class="modal-body no-padding">
				<div class="row">
					<div class="col-xs-12">
						<form class="form-horizontal mt10" id="publisher-form">
							<input type="hidden" name="id" />
							<div class="form-group">
								<label class="col-sm-3 control-label no-padding-right">出版社标题：</label>
								<div class="col-sm-6">
									<input class="form-control" type="text" placeholder="请填写出版社标题" value="" name="title" />
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
			<div class="modal-footer no-margin-top" >
				<a href="javascript:;" class="btn btn-sm btn-primary" id="save-publisher">
					<i class="ace-icon fa fa-check"></i> 保存
				</a>
			</div>
		</div>
	</div>
</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	var table = "";
	$(function(){
		// 出版社列表
		table = $('#dynamic-table').dt({
			"ajaxUrl": '<?=admin_url('admin/get_source_publisher_list')?>',
			"columns": [

                {"data": function(ret){
	            	return ret.title;
                }},
                {"data": function(ret){
	            	return ret.createtime;
                }},
                {"data": function(ret){
	            	return ret.updatetime;
                }},											
	            {"data": function(ret){
					var action = '';
						action += '<a class="edit-source-publisher" href="#modal-publisher" data-toggle="modal" data-id="' + ret.id + '" data-title="' + ret.title + '" class="mr10"><i class="fa fa-edit"></i> 修改</a>&nbsp;&nbsp;&nbsp;&nbsp;';
	            		action += '<a class="delete-source-publisher text-danger" href="javascript:;" data-id="'+ ret.id + '" data-title="' + ret.title + '" ><i class="fa fa-times"></i> 删除</a>';
	                return action;
	            }}
			]
		});
    })
    // 保存资源出版社按钮
    var publisherForm = $("#publisher-form");
    $("#save-publisher").click(function(){
        publisherForm.submit();
    })
    var submitUrl = "<?=admin_url('admin/save_source_publisher_action')?>";
    form_submit(publisherForm, submitUrl, function(res) {
        tips_alert(res.msg, res.success, function(){
            if(res.success) window.location.reload();
        });
    })
    // 编辑出版社
    $("body").on("click", ".edit-source-publisher", function(){
        publisherForm.find("[name=id]").val($(this).data("id"))
        publisherForm.find("[name=title]").val($(this).data("title"))
    })
    // 删除出版社
    $("body").on("click", ".delete-source-publisher", function(){
        var id = $(this).data("id");
        var title = $(this).data("title");
        layer.confirm("确定删除出版社 '" + title + "' 吗？", function(){
            // 提交数据
            var postUrl = "<?=admin_url('admin/delete_source_publisher_action')?>";
            var postData = {"id": id};
            ajax_post(postUrl, postData, function(res){
                table.draw(false);
            })
        });
    })
</script>